package com.candy.control;

import com.candy.service.UserInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedList;

/**
 * 在web.xml中配置的servlet与注解配置的内容不能重复
 * */
@WebServlet("/getUserInfoes")
public class GetUserInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        处理中文乱码问题
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        接收前端传递进来的参数
        String username=req.getParameter("username");
//        调用业务逻辑处理层
        UserInfoService service=new UserInfoService();
        LinkedList<LinkedHashMap<String,Object>> userinfoes= service.getUserInfoes(username);
//        将数据返回给前端
        req.getSession().setAttribute("userinfoes",userinfoes);
//        跳转页面
        req.getRequestDispatcher("userinfomanager.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
